import Pool from "../Pool"
import cjs=createjs
import Global from "../Global"
//import createjs from "../../createjs"

export default class Enemy extends cjs.Container{
    width=0
    height=0
    recover=false
    private _enemy
    constructor(){
        super()
        this.name='enemy'
        const lib=Global.getLibrary()
        this._enemy=new lib.EnemyBitmap()
        this.addChild(this._enemy)
        const rect=this._enemy.getBounds()
        this.width=rect.width
        this.height=rect.height
        console.log('new Enemy')
    }
    getBounds(): cjs.Rectangle {
        return this._enemy.getBounds()
    }
    /*setImage(img:any):void{
        this.image=img
        const rect=this.getBounds()
        this.width=rect.width
        this.height=rect.height
    }*/
    move():void{
        const put=()=>{
            this.off('tick',listener)
            const parent=this.parent as cjs.Container
            parent.removeChild(this)
            Pool.getInstance().recover('Enemy',this)
        }
        const listener=this.on('tick',():void=>{
            this.y+=6
            if(this.y>Global.stageHeight){
                put()
            }else if(this.recover){
                put()
            }
        })
    }
}